// app.js
const httpServer = require("./utils/api");

App({
  onLaunch() {
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.error(res)
      }
    })

    this.calculateNavBarHeight();
  },

  // 获取设备信息
  calculateNavBarHeight() {
    // 计算逻辑...
    const systemInfo = wx.getWindowInfo();
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    
    // 状态栏高度（iPhoneX等异形屏需特殊处理）
    const statusBarHeight = systemInfo.statusBarHeight;
    const screenWidth = systemInfo.screenWidth;
    const pixelRatio = systemInfo.pixelRatio;
    
    // 导航栏总高度 = 状态栏高度 + 胶囊按钮高度 + 上下间距
    const navBarHeight = menuButtonInfo.top + menuButtonInfo.height + 10;
    const navBarWidth = menuButtonInfo.width + 10; // 胶囊按钮宽度
    this.globalData.WindowInfo = {
      navBarHeight,
      statusBarHeight,
      navBarWidth,
      screenWidth,
      pixelRatio
    }
  },
  globalData: {
    httpServer,
    userInfo: null,
    WindowInfo: {
      navBarHeight: null,
      statusBarHeight: null,
      pixelRatio: 1,
    }
  }
})
